package ee.serge;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class FileHelper {

   public static char[][] read(String path) throws IOException {
      FileInputStream fstream = new FileInputStream(path);
      DataInputStream in = new DataInputStream(fstream);
      BufferedReader br = new BufferedReader(new InputStreamReader(in));
      String strLine;
      List<String> inputList = new ArrayList<String>();
      strLine = br.readLine();
      if (strLine.length() > 9) {
         inputList.add(strLine);
      }
      while ((strLine = br.readLine()) != null) {
         inputList.add(strLine);
      }
      in.close();
      char[][] maze = new char[inputList.size()][inputList.size()];
      for (int y = 0; y < inputList.size(); y++) {
         String line = inputList.get(y);
         for (int x = 0; x < line.length(); x++) {
            char c = line.charAt(x);
            maze[x][y] = c;
         }
      }
      return maze;
   }
   
   public static void write(String path, List<Integer> list) throws IOException {
      FileWriter fstream = new FileWriter(path);
      BufferedWriter out = new BufferedWriter(fstream);
      for (Integer i : list) {
         out.write(String.valueOf(i) + "\n");
      }
      out.close();
   }
   
}
